package vip.liux.backend.adapter.web.account;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserCache;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/account/user")
public class UserController {

    private final UserCache userCache;

    public UserController(UserCache userCache) {
        this.userCache = userCache;
    }

    @GetMapping("/info")
    public Map<String, Object> info(Authentication authentication) {
        return Map.of(
                "userInfo", userCache.getUserFromCache(authentication.getName()),
                "roles", Map.of("isSuper", true, "permissions", new String[]{})
        );
    }
}
